import { Web3 } from "web3";


export class ConnectStore {
    web3: Web3 | null = null


    setWeb3(web3: Web3) {
        this.web3 = web3
    }

    async sign(obj:Object):Promise<string>{
        let hexString =  this.web3?.utils.soliditySha3(obj)!;

        let accounts = await window.ethereum.request({
            method: 'eth_requestAccounts',
        });
        return await this.web3?.eth.personal.sign(hexString,accounts[0],'')!;
    }

    async signStr(obj:string):Promise<string>{
        let hexString =  this.web3?.utils.utf8ToHex(obj)!;

        let accounts = await window.ethereum.request({
            method: 'eth_requestAccounts',
        });
        return await this.web3?.eth.personal.sign(hexString,accounts[0],'')!;
    }

}



